# -*- coding: utf-8 -*-
'''
Created on 2011-3-31

@author: Tony
'''
import unittest
from goplay.weibopy.auth import OAuthHandler
from goplay.weibopy.api import API

class update(unittest.TestCase):
    
    consumer_key= "3482834712"
    consumer_secret ="40c54f7f6730f543aed36b36f92ca06e"
    
    def __init__(self):
            """ constructor """
    
            
    def auth(self):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        auth_url = self.auth.get_authorization_url()
        print 'Please authorize: ' + auth_url
        verifier = raw_input('PIN: ').strip()
        self.auth.get_access_token(verifier)
        self.api = API(self.auth)
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception, e:
            print e
            return ''
        
    def getAttValue(self, obj, key):
        try:
            return obj.__getattribute__(key)
        except Exception, e:
            print e
            return ''
    def setToken(self, token, tokenSecret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setToken(token, tokenSecret)
        self.api = API(self.auth)
    
    def publishWeibo(self,content):
        #content = content.encode("utf-8")
        status=self.api.update_status(status=content)
        self.obj=status

    
    def send(self,token,tokenSecret,content):
        u=update()
        u.setToken(token, tokenSecret)
        u.publishWeibo(content)
        return 'successfully'

''''u=update()
m=u.send("3d6bf54fce077e12f236e67a2ef6e886", "fea2e9c69bae15088bf9aa116c371ea8",'这下正常了～～～～')
print m'''